<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>添加奖惩记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form ref="infoForm" label-width="140px">
          <el-form-item label="奖惩类型:" prop="name">
            <el-radio-group v-model="fromOption.type">
              <el-radio :label="0">奖</el-radio>
              <el-radio :label="1">惩</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="奖惩内容:" prop="name">
            <el-input v-model="fromOption.content" placeholder="填写奖惩" type="textarea"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="submitFromFn" size="small" type="primary">确定并保存
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
// recruitmentType first 在用查看招聘 ; history 历史查看招聘 ; examine 审核查看招聘
export default {
  props: ['visible','id'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      fromOption:{
        archives_id: this.id,
        type: 0,
        content: ''
      }
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
    }
  },
  created() {

  },
  methods: {
    submitFromFn(type, option) {
      // 参数判断
      if (!this.fromOption.content) {
        this.$message.error('填写奖惩说明')
        return
      }
      this.$post(this.api.archives.reward.add, this.fromOption).then((response) => {
        if (!response.code) {
          this.$message.success(response.msg)
          this.$emit('addInit')
          this.closePOpup()
        } else {
          this.$message.error(response.msg)
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 获取详情
    async InitFn() {
      let data = await this.$fetch(this.api.recruit.resume.edit, {id: this.resumeId});
      console.log('data物料信息:', data)
      if (!data.code) {
        if (data.vo.experience) {
          let a = data.vo.experience.split('-')
          this.starYear = a[0]
          this.endYear = a[1]
        }
        this.examine_user_tag = [this.getJson(data.recruit_examine_user)]
        this.examine_user = this.getJson(data.recruit_examine_user);
        // employ_user  interview_user
        let interview_user = this.getJson(data.vo.interview_user);
        for (let i in interview_user) {
          this.dynamicTags_interview.push(interview_user[i])
          this.dynamicTagsId_interview.push(interview_user[i].id)
          this.dynamicTagsArray_interview[interview_user[i].id] = interview_user[i]
        }
        console.log('dynamicTagsId_interview:', this.dynamicTagsId_interview)

        let employ_user = this.getJson(data.vo.employ_user);
        for (let i in employ_user) {
          this.dynamicTags_employ.push(employ_user[i])
          this.dynamicTagsId_employ.push(employ_user[i].id)
          this.dynamicTagsArray_employ[employ_user[i].id] = employ_user[i]
        }
        console.log('dynamicTagsId_employ:', this.dynamicTagsId_employ)

        this.editOption.recruit_examine_user = this.examine_user.id
        this.editOption.interview_user = this.dynamicTagsId_interview.join(',');
        this.editOption.employ_user = this.dynamicTagsId_employ.join(',');

        this.requirements = this.getJson(data.vo.requirements)
        for (let i in this.editOption) {
          if (i !== 'recruit_examine_user' && i !== 'interview_user' && i !== 'employ_user' && i !== 'requirements') {
            if (data.vo[i]) {
              this.editOption[i] = data.vo[i]
            }
          }
        }

        console.log('编辑整理的数据：', this.editOption)
        // this.dynamicTags_employ = [];
        // this.dynamicTagsId_employ = [];
        // this.dynamicTagsArray_employ = {};
        // editOption: {
        //   job_id: '',// 	字符串 	必填 	1 	- 	招聘岗位id
        //       number: '',// 	字符串 	必填 	1 	- 	招聘人数
        //       treatment: '',// 	字符串 	必填 	1 	- 	待遇
        //       trial_time: '',//	字符串 	必填 	1 	- 	使用期限
        //       end_time: '',// 	字符串 	必填 	1 	- 	结束时间
        //       sex: 0,// 	字符串 	必填 	1 	- 	性别0不限1男2女
        //       age: '',// 	字符串 	必填 	1 	- 	年龄（以上）
        //       education: '',//	字符串 	必填 	1 	- 	学历id
        //       experience: '',//	字符串 	必填 	1 	- 	工作经验
        //       requirements: '',//	字符串 	必填 	1 	- 	岗位要求json
        //       recruit_examine_user: '',//	字符串 	必填 	1 	- 	简历审核人
        //       interview_user: '',//	字符串 	必填 	1 	- 	面试考核人员id多选逗号隔开
        //       employ_user: '',//	字符串 	必填 	1 	- 	录用考核人员id多选逗号隔开
        // }, // 编辑界面数据
        // starYear: '',
        //     endYear: '',
        //     typeJob: 1, // 工作性质
        //     credit: 1, // 征信
      } else {
        this.$message.error(data.msg)
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 40%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


